"use strict"
var call = require("../../utils/request.js")
const app = getApp()
Page({
  data: {
      goodsList: [],
      pingjia:'0',
      imgList: [],
      stars: [0, 1, 2, 3, 4],
      normalSrc: '../../static/icon/normal.png',
      selectedSrc: '../../static/icon/selected.png',
      halfSrc: '../../images/half.png',
      key: 0,//评分
      wskey:0,
      hjkey:0,
      fwkey:0,
      sskey:0,
      hid:'',
      memo:'',
      ordernum:'',
      htitle:'',
      rtitle:'',
      image:''
  

  },

  onLoad: function(e) {

    if (wx.getStorageSync("uid")) {
    
        this.setData({
          hid: e.hid,
          ordernum:e.ordernum
        })


        var call = require("../../utils/request.js")
        var url = 'getroomdetail?roomid='+e.hid
        call.getData(url, this.gethdetail, this.fail)

       
    } else {

      setTimeout(() => {
        wx.showToast({
          title: '请先授权登录',
          icon: "none",
        });
        setTimeout(() => {
          wx.switchTab({
            url: '../mine/mine'
          })
        }, 2000)
      }, 0);
    }

  },
  gethdetail: function(e) {

      console.log(e.data)
   
     
      this.setData({
        htitle: e.data.h,
        rtitle:e.data.r,
        image:e.data.image
      })
  },

  addData: function(e) {
    var goods = this.data.pingjia
      if(goods == 0){
        wx.showToast({
          title: '请先评价',
          icon: "none",
        });
        return false
      }

      var memo = this.data.memo
     
        if(memo == 0){
          wx.showToast({
            title: '请先评价',
            icon: "none",
          });
          return false
        }
        var wskey = this.data.wskey
 
          if(wskey == 0){
            wx.showToast({
              title: '请先打分',
              icon: "none",
            });
            return false
          }
          var hjkey = this.data.hjkey
 
          if(hjkey == 0){
            wx.showToast({
              title: '请先打分',
              icon: "none",
            });
            return false
          }

          var fwkey = this.data.fwkey
 
          if(fwkey == 0){
            wx.showToast({
              title: '请先打分',
              icon: "none",
            });
            return false
          }

          var sskey = this.data.sskey
 
          if(sskey == 0){
            wx.showToast({
              title: '请先打分',
              icon: "none",
            });
            return false
          }



    var url = 'getcomments?uid=' + wx.getStorageSync("uid")+'&goods='+goods+'&memo='+memo+'&wskey='+wskey+'&hjkey='+hjkey+'&fwkey='+fwkey+'&sskey='+sskey+'&roomid='+this.data.hid+'&ordernum='+this.data.ordernum
    call.getData(url, this.getcomments, this.fail)


  }, 

  
  getcomments: function(e) {
      console.log(e)
      if(e == 1){
        setTimeout(() => {
          wx.showToast({
            title: '评论成功',
            icon: "none",
          });
          setTimeout(() => {
            wx.reLaunch({
              url: '../index/index'
            })
          }, 2000)
        }, 0);
      }else{
        wx.showToast({
          title: '评论失败',
          icon: "none",
        });
      }
  },
  searchInput: function(e) {
  
    this.setData({
      memo:e.detail.value
    }) 
  }, 
  selectLeftweisheng: function (e) {
    var wskey = e.currentTarget.dataset.key
    if (this.data.wskey == 0.5 && e.currentTarget.dataset.key == 0.5) {
      //只有一颗星的时候,再次点击,变为0颗
      wskey = 0;
    }
    console.log("得" + wskey + "分")
    this.setData({
      wskey: wskey
    })

  },

  selectLefthuanjing: function (e) {
    var hjkey = e.currentTarget.dataset.key
    if (this.data.hjkey == 0.5 && e.currentTarget.dataset.key == 0.5) {
      //只有一颗星的时候,再次点击,变为0颗
      hjkey = 0;
    }
    console.log("得" + hjkey + "分")
    this.setData({
      hjkey: hjkey
    })

  },


  selectLeftfuwu: function (e) {
    var fwkey = e.currentTarget.dataset.key
    if (this.data.hjkey == 0.5 && e.currentTarget.dataset.key == 0.5) {
      //只有一颗星的时候,再次点击,变为0颗
      fwkey = 0;
    }
    console.log("得" + fwkey + "分")
    this.setData({
      fwkey: fwkey
    })

  },


  selectLeftsheshi: function (e) {
    var sskey = e.currentTarget.dataset.key
    if (this.data.hjkey == 0.5 && e.currentTarget.dataset.key == 0.5) {
      //只有一颗星的时候,再次点击,变为0颗
      sskey = 0;
    }
    console.log("得" + sskey + "分")
    this.setData({
      sskey: sskey
    })

  },


  chooseImage: function (data) {
    var that = this
  
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success (res) {
  
          that.data.imgList.push(res.tempFilePaths[0])
  
        that.setData({
          imgList: that.data.imgList
        })

      }
    })
  },


  stateType: function (data) {

    this.setData({
      pingjia: data.currentTarget.dataset.item
    })

    console.log(this.data.pingjia)
  },





  gohome: function (data) {
    wx.reLaunch({
      url: '../index/index',
    })
  },






})